<template>
	<view>
		<view v-if="logingTrue" style="background-color: transparent;z-index: 9999;width: 100%;height: 100vh;position: absolute;top: 0;left: 0;">
			<u-navbar
				:placeholder="true"
				bgColor="transparent"
			>
				<view slot="left">
					<span></span>
				</view>	
			</u-navbar>
			<view style="background-color:#f7f8ff;height: 100%;">
				<u-loading-icon mode="circle" color="rgb(3, 121, 255)" size="30"></u-loading-icon>
			</view>
			
		</view>

		<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
		<u--form labelPosition="left" labelAlign="left" :model="itemKeyList" ref="formRef" labelWidth="80" >
			<u-form-item
			 v-for="(item, index) in itemListNew"
			 :key="index"
			 :label="item.label" 
			 :required="item.required"
			 :prop="item.model"
			 :borderBottom="item.borderBottom || true"
			 >
				<u--input :disabled="item.disabled" v-if="item.type == 'input'" v-model="itemKeyList[item.model]" :border="item.border || 'none'" :placeholder="item.placeholder || '请选输入'" :maxlength="item.maxlength || 50"></u--input>
				<view @click="item.disabled? '' : focusFun(item)"  v-if="item.type == 'select'">
					<u--input readonly  v-model="itemKeyList[item.model]"  disabledColor="#ffffff" :placeholder="item.placeholder || '请选择'" border="none"></u--input>
				</view>
				<view @click="item.disabled? '' : adderFun(item)"  v-if="item.type == 'address'">
					<u--input readonly  v-model="itemKeyList[item.model]"  disabledColor="#ffffff" :placeholder="item.placeholder || '请选择'" border="none"></u--input>
				</view>
				<!-- 单选选择 -->
				<div v-if="item.type == 'radio'">
					<u-radio-group 
					 @change="groupChange"
					v-model="itemKeyList[item.model]"
					placement="row">
						<u-radio :disabled="item.disabled" :name="1" label="线下">线下</u-radio>
						<u-radio :disabled="item.disabled" style="margin-left: 20rpx;" :name="2" label="线上">线上</u-radio>
					</u-radio-group>
				</div>
				<view @click="item.disabled? '' : focusFun(item)"  v-if="item.type == 'selectMd'">
					<u--input readonly  v-model="itemKeyList[item.model]"  disabledColor="#ffffff" :placeholder="item.placeholder || '请选择'" border="none"></u--input>
				</view>
				
				<view style="display: flex;justify-content: flex-end; width: 100rpx;height: 50rpx;"  v-if="item.type == 'selectMd'" slot="right" @click="targetFun(item)">
					<u-icon color="rgb(3, 121, 255)" v-if="item.type == 'selectMd'" name="edit-pen-fill"></u-icon>
				</view>
				<view v-show="(item.type == 'select' || item.type == 'address') && !item.look" slot="right">
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view style="display: flex;justify-content: flex-end; width: 100rpx;height: 50rpx;" v-if="item.look" slot="right">
					<u-icon @click="lookPdfImgFun(item)"  v-show="item.look" color="rgb(3, 121, 255)" name="eye"></u-icon>
				</view>
				<uniDataPicker v-if="item.type == 'addressArea'"   @change="addresFun($event, item)" :localdata="datasgs" :map="{text:'cityName',value:'id'}" popup-title="选择城市">
				 <view style="display: flex;align-items: center;" @click="addressAreaFun">
						<u--input readonly  v-model="itemKeyList[item.model]"  disabledColor="#ffffff" :placeholder="item.placeholder || '请选择'" border="none"></u--input>
						<u-icon name="arrow-right"></u-icon>
				 </view>
				</uniDataPicker>
				<view v-if="item.type == 'file'">
					<!-- mutiple  label 是否允许上传一次性上传多张 -->
					<u-upload
						:fileList="item.fileList"
						@afterRead="afterRead($event, item)"
						@delete="deletePic($event, item)"
						:mutiple="false"
						:disabled="item.disabled"
						:accept="item.documentType == 'img'? 'image' : 'all'"
						name="1"
						:maxCount="item.imit || 2"
						width="50"
						height="50"
					>
						<view class="add_sty">
							<u-icon name="plus"></u-icon>
						</view>
					</u-upload>
					<view style="margin: 30rpx 0;display: flex;align-items: center;" v-for="(itemmin, indexs) in itemKeyList[item.documentList]" :key="indexs">
						<span style="display: block;width: 420rpx;">{{ itemmin.name }}</span>
						<u-icon @click="deletePic($event, item)" style="margin-left: 20rpx;" name="trash"></u-icon>
					</view>
				</view>
				<view v-if="item.type == 'textarea'" style="width: 100%;position: relative;">
					<u--textarea :disabled="item.disabled" confirmType="done" :count="false" v-model="itemKeyList[item.model]" placeholder="请输入内容" :placeholder="item.placeholder || '请输入'" ></u--textarea>
				</view>
				<view style="width: 100%;position: relative;" @click="showTpye(item)" v-if="item.type == 'mulSelect'">
					<textarea readonly="true" style="width: 100%;height: 200rpx;border:1px solid gainsboro; pointer-events: none;" :disabled="item.disabled" confirmType="done"  placeholder="请选择" v-model="itemKeyList[item.model]"  suffixIcon="arrow-down"></textarea>
				</view>
			</u-form-item>
			
		</u--form>
		<u-picker :closeOnClickOverlay="false" v-if="showSex" :show="showSex" :columns="actions" :keyName="keyName" :title="title" :defaultIndex="indexItem"
			@cancel="showSex = false" @confirm="sexSelect($event)">
		</u-picker>
		 <u-datetime-picker
			:show="showTime"
			v-model="newTime"
			mode="datetime"
			@cancel="showTime = false"
			@confirm="confirmTime($event)"
			:formatter="formatter"
		> </u-datetime-picker>
		<view class="mySelect">
			<u-popup :show="checkboxShow" @close="checkboxShow=false" :round="10" closeOnClickOverlay>
			    <div class="checkbox">
						<u-checkbox-group size='27' borderBottom iconSize='18' iconPlacement='right' v-model="itemKeyList[mulData]" placement="column">
							<u-checkbox  :disabled="item.disabled" :customStyle="{marginBottom: '8px'}"  v-for="(item, index) in list" :key="index" :label="item.name || item.dictLabel" :name="item.id || item.dictValue"></u-checkbox>
						</u-checkbox-group>
						<div class="btnList">
							<u-button class="btn" type="primary" color="#909399" text="清空选择" @click="checkboxDel"></u-button>
							<div style="width: 40rpx;"></div>
							<u-button type="primary" color="rgb(3, 121, 255)" text="确定" @click="checkboxConfirm"></u-button>
						</div>
			    </div>
			</u-popup>
		</view>
		<u-modal v-if="showTarget" :show="showTarget" @confirm="confirmFun">
			<view class="slot-content" style="width: 90%;position: relative;">
				<u--textarea v-if="model == 'target'" style="width: 95%;"  confirmType="done"  v-model="itemKeyList.target"  placeholder='请输入目的' ></u--textarea>
				<u--textarea v-if="model == 'doctorIdea'" style="width: 95%;"  confirmType="done"  v-model="itemKeyList.doctorIdea"  placeholder='请输入反馈' ></u--textarea>
			</view>
		</u-modal>
		<u-modal v-if="showTimefilter" :show="showTimefilter" @cancel="showTimefilter = false" @confirm="confirmFunXz" showCancelButton :content='contentext+"是否提交？"'></u-modal>
	</view>
</template>

<script>
	import uniDataPicker from './uni-data-picker/components/uni-data-picker/uni-data-picker.vue'
	import Config from '@/core/config'
	import request from '@/utils/request'
	const apiUrl = Config.get('apiUrl')
	export default {
		components:{uniDataPicker},
		props: {
		 itemList: {
				type: Array,
				default: [],
			},
			itemKeys: {
				type: Object,
				default: {}
			},
		},
		// onReady() {
		// 	console.log('fasdgs')
		// 	this.$refs.formRef.setRules(this.rules);
		// },
		data() {
			return {
				pafList: [],
				contentext: '',
				showTimefilter: false,
				logingTrue: true,
				showTarget: false,
				area: [],
				datasgs: [],
				datasg: [],
				keys: '',
				mulData: '',
				checkedList: [],
				list: [],
				checkboxShow: false,
				documentList: [],
				fileList1: [],
				showTime: false,
				itemKeyList: {
					
				},
				itemListNew: [],
				controls: '',
				newTime: new Date().getTime(),
				indexItem: [0],
				showSex: false,
				
				actions: [],
				keyName: '',
				title: '',
				radio: '',
				switchVal: false,
				model: '',
				value: '',
				modelName: '',
				parms: '',
			};
		},
		watch: {
			itemKeys: {
				handler(val) {
					this.itemKeyList = this.itemKeys
					this.setdata()
				},
				deep: true,
				immediate: true
			},
			itemList: {
				handler(val) {
					if (val) {
						// this.itemListNew = JSON.parse(JSON.stringify(this.itemList))
						// this.itemListNew = JSON.parse(JSON.stringify(this.itemList))
						this.itemListNew = JSON.parse(JSON.stringify(this.itemList)).slice(0, 4)
						setTimeout(() => {
							this.itemListNew = [...JSON.parse(JSON.stringify(this.itemList)).slice(0, 4), ...JSON.parse(JSON.stringify(this.itemList)).slice(4, JSON.parse(JSON.stringify(this.itemList)).length)]
							if (this.itemKeys.pattern == 1) {
								this.itemListNew.forEach((val) => {
									if (val.domType) {
										val.label = '签到表'
										val.message = '请选择签到表'
									}
								})
							} else {
								// 线上
								this.itemListNew.forEach((val) => {
									if (val.domType) {
										val.label = '参会人员明细'
										val.message = '请选择参会人员明细'
									}
								})
							}
							
							if(this.itemKeys.resourceId){
								this.itemListNew.forEach((val) => {
									if (val.model == 'resourceName') {
										if (!val.actions.length) {
											request.get('/task/resource/list').then((res)=> {
												res.rows.forEach((item) => {
													if (item.id == this.itemKeys.resourceId) {
														// this.itemKeyList.resourceName = item.name
														this.$set(this.itemKeys, 'resourceName', item.name)
														this.$set(this.itemKeys, 'resourceName', item.name)
														this.$refs.formRef.validateField(val.model)
														// this.keys = new Date().getTime()
													}
												})
											})
										}
									}
									// console.log('item.look', item.look)
									if (val.look) {
										let parm = {pageNum: 1,
										pageSize: 1000,
										drugId: this.itemKeyList.drugId}
										request[val.apiType || 'get'](val.url, parm).then((res) => {
											this.pafList = res[val.dataType] || res.data
											// this.keys = new Date().getTime() item
										})
									}
								})
							}
							if (this.itemKeys.photoList && this.itemKeys.photoList.length > 0) {
									this.itemListNew.forEach((items) => {
										items.fileList = []
										this.itemKeys.photoList.forEach((val) => {
											if (items.category === 1 || items.category === 0) {
												if (items.fileList && (items.fileType == val.type && items.category == val.category)) {
													val.id = ''
													items.fileList.push(val)
													this.itemKeys[items.model] = val.url
												}
											} else {
												if (items.fileList && (items.fileType == val.type)) {
													val.id = ''
													items.fileList.push(val)
													this.itemKeys[items.model] = val.url
												}
											}
										})
										
									})
							}
							this.itemListNew.forEach((items) => {
								if (items.changeFunflie) {
									items.fileList = this.itemKeys.documentList
									this.itemKeys[items.model] = this.itemKeys.documentList?.[0]?.url
								}
							})
							
							this.setdata()
						}, 500)
						// this.keys = new Date().getTime()
						// setTimeout(() => {
						// this.itemListNew = [...this.itemListNew, ...JSON.parse(JSON.stringify(this.itemList)).slice(4, JSON.parse(JSON.stringify(this.itemList)).length)]
						this.itemListNew.forEach((val) => {
							if (val.type == 'addressArea') {
								request.get('/base/city/getCityTree').then((res)=> {
									this.datasgs = res.data
									this.setdata()
								})
							}
						})
						// }, 500)
					}
				},
				immediate: true,
				deep: true
			}
		},
		
		mounted() {
			// uni.hideLoading()
			// this.itemKeyList = JSON.parse(JSON.stringify(this.itemKeys))
			// this.itemListNew = JSON.parse(JSON.stringify(this.itemList))
			// setTimeout(() => {
			// 	this.itemListNew = [...this.itemListNew, ...JSON.parse(JSON.stringify(this.itemList)).slice(4, JSON.parse(JSON.stringify(this.itemList)).length)]
			// }, 500)
			setTimeout(() => {
				this.logingTrue = false
				this.itemKeyList = this.itemKeys
			}, this.itemListNew.length*80)
		},
		onLoad() {
			// uni.hideLoading()
			this.setdata()
		},
		onShow() {
			// uni.hideLoading()
		},
		methods: {
			delPdfFun() {
				
			},
			lookPdfImgFun(items) {
				if (this.itemKeyList[items.model]) {
					this.pafList.forEach((item) => {
						if (item.name == this.itemKeyList[items.model]) {
							if (item.url.split('.')[item.url.split('.').length-1] == 'pdf') {
								uni.navigateTo({
									url: '/pages/pdfLook/index?url=' + item.url
								})
							} else {
								uni.previewImage({
										current: 0,
										urls: [item.url],
								})
							}
							// uni.downloadFile({//下载对应文件
							// 		url: item.url, // 下载文件网络地址
							// 		success: function (res) {
							// 			console.log('fasdg324235', res)
							// 				var filePath = res.tempFilePath;//本地文件路径    
							// 				uni.openDocument({
							// 						filePath: filePath,   // 装载对应文件的路径
							// 						fileType: 'jpg',   // 指定打开的文件类型 我写的固定类型 也可根据文件的后缀动态设置
							// 						showMenu: true,       // 右上角的菜单转发分享操作
							// 						success: function (res) {
							// 								console.log('打开成功');
							// 						},
							// 						fail: function (err) {
							// 								console.log('打开失败：', err);
							// 						}
							// 				})
							// 		}
							// })
						}
					})
				}
				
			},
			groupChange(e) {
				if (e == 1) {
					this.itemListNew.forEach((val) => {
						if (val.domType) {
							val.label = '签到表'
							val.message = '请选择签到表'
						}
					})
				} else {
					// 线上
					this.itemListNew.forEach((val) => {
						if (val.domType) {
							val.label = '参会人员明细'
							val.message = '请选择参会人员明细'
						}
					})
				}
				this.setdata()
				// this.$emit('patternFun', e)
			},
			setitemKeyList() {
				return this.itemKeyList
			},
			confirmFun() {
				this.showTarget = false
			},
			targetFun(item) {
				this.model = item.model
				this.modelName = item.modelName
				this.showTarget = true
			},
			addressAreaFun() {
				if (this.datasgs.length > 0) {
					return
				}
				request.get('/base/city/getCityTree').then((res)=> {
					this.datasgs = res.data
				})
			},
			addresFun(e, item) {
				this.itemKeyList[item.model] = ''
				e.detail.value.forEach((val, index) => {
					if (e.detail.value.length-1 == index) {
						this.itemKeyList[item.model]+= val.text
					} else {
						this.itemKeyList[item.model]+= val.text + '/'
					}
				})
				
				// console.log('fasdg25', this.itemKeyList)
			},
			bindPickerChange() {
				let area = val.detail.value
				this.area = [area[0].text,area[1].text,area[2].text];
				this.address.province = area[0].value;
				this.address.city = area[1].value;
				this.address.county = area[2].value;
			},
			setdata() {
				
				let rules = {}
				// this.setdata() setRules
				this.$nextTick(() => {
					this.$refs.formRef.setRules(rules);
				})
				
				this.itemListNew.forEach((val) => {
					
					if (val.required) {
						rules[val.model] = [
							{
								required: true,
								message: val.message,
								// 可以单个或者同时写两个触发验证方式
								trigger: ["change", "blur"],
							}
						]
						if (val.test == 'mobile') {
							// 验证手机号
							rules[val.model].push({
									validator: (rule, value, callback) => {
										return uni.$u.test.mobile(value);
									},
									message: '请输入合法的手机号码',
									trigger: ['change','blur'],
							})
						}
						if (val.test == 'digits') {
							// 验证整数
							rules[val.model].push({
									validator: (rule, value, callback) => {
										return uni.$u.test.digits(value);
									},
									message: '请输入合法的数字',
									trigger: ['change','blur'],
							})
						}
						if (val.test == 'idCard') {
							// 验证身份证好
							rules[val.model].push({
									validator: (rule, value, callback) => {
										return uni.$u.test.idCard(value);
									},
									message: '请输入合法的身份证',
									trigger: ['change','blur'],
							})
						}
					}
				})
			},
			checkboxDel() {
				this.itemKeyList[this.mulData] = []
				this.itemKeyList[this.model] = ''
				this.$refs.formRef.validateField(this.model)
			},
			checkboxConfirm() {
				if (!this.itemKeyList[this.mulData]?.length) {
					uni.showToast({
					  title: '请最少选择一个医院',
					  icon: "none",
					  duration: 2500,
					})
					return
				}
				this.itemKeyList[this.modelName] = []
				let arr  = []
				this.list.forEach((val,index) => {
					if (this.itemKeyList[this.mulData].includes(val.id||val.dictValue)) {
						arr.push(val.name||val.dictLabel)
						this.modelName && this.itemKeyList[this.modelName].push({
							hospitalId: val.id||val.dictValue
						})
					}
				})
				// console.log('h15', this.itemListNew[this.model])
				// this.itemListNew[this.model] = 1235
				this.itemKeyList[this.model] = arr.toString()
				this.checkboxShow = false
				this.$refs.formRef.validateField(this.model)
			},
			showTpye(item) {
				this.model = item.model
				this.modelName = item.modelName
				this.mulData = item.mulData
				if (item.type == 'mulSelect') {
					let str = {}
					if (item.provinceFil) {
						str.province = this.itemKeyList.province
					}
					request.get(item.url, {pageNum: 1,pageSize: 1000, ...str}).then((res)=> {
						this.list = res.rows || res.data
						if (item.filter) {
							let arr = JSON.parse(uni.getStorageSync('userInfoRole')).hospitalList.map(item => item.hospitalId)
							this.list = this.list.filter(item => arr.includes(item.id))
						}
						this.checkboxShow = true
					})
				}
				
				
			},
			adderFun(item) {
				this.$emit('setAdders', true)
			},
			// 删除图片
			deletePic(event, item) {
				item.fileList.splice(event.index, 1)
				if (item.fileList.length == 0) {
					this.itemKeyList[item.model] = ''
				}
				
				// this.itemKeyList.photoList = []
				// this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event, item) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let _this = this
				uni.uploadFile({
					url: apiUrl + '/file/upload',
					filePath: event.file.url,
					name: "file",
					header: {
						'token': uni.getStorageSync('token')
					},
					success: (val) => {
						let res = JSON.parse(val.data)
						if (item.documentType == 'img') {
							item.fileList.push({
								url: res.data.url,
								type: item.fileType,
								category: item.category || 0
							})
						} else {
							_this.itemKeyList[item.documentList].push({
								name: event.file.name,
								url: res.data.url
							})
						}
						// if(item.modelName){
						// 	_this.itemKeyList[item.modelName].push({
						// 		type: item.fileType,
						// 		url: res.data.url,
						// 		category: item.category || 0
						// 	})
						// }
						_this.itemKeyList[item.model] = res.data.url
						// _this.itemKeyList.urlFil = res.data.url
						// photoList
						
						if (item.changeFun) {
							this.$emit('changeFun', res.data.url)
						}
						if (item.changeFunflie) {
							this.$emit('changeFun', {
								agreementList: _this.itemKeyList[item.documentList],
								fileType: item.fileType
							})
							// _this.itemKeyList[item.documentList] = []
						}
					},
				});
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			focusFun(item) {
				this.parms = item.parm
				this.controls = item.controls
				this.keyName = item.keyName
				this.value = item.value
				this.model = item.model
				this.modelName = item.modelName
				let parm = {}
				if (item.urlId) {
					parm = {
						id: this.itemKeyList.hospitalId || this.itemKeyList.hospitalList[0].hospitalId
					}
				} else if(item.urlObj) {
					if (item.parm) {
						parm = {
							hospitalId: this.itemKeyList.hospitalId || this.itemKeyList.hospitalList[0].hospitalId || null,
							departmentId: this.itemKeyList.departmentId || null,
							...item.parm,
						}
					} else {
						parm = {
							hospital: this.itemKeyList.hospitalId || this.itemKeyList.hospitalList[0].hospitalId || null,
							department: this.itemKeyList.departmentId || null,
						}
					}
					
				}else if (item.owner) {
					parm = {
						pageNum: 1,
						pageSize: 1000,
						owner: 2
					}
				} else if (item.drugIds) {
					parm = {
						pageNum: 1,
						pageSize: 1000,
						drugId: this.itemKeyList.drugId
					}
				} else if (item.provinceFil) {
					parm = {
						pageNum: 1,
						pageSize: 1000,
						province: this.itemKeyList.province
					}
				} else {
					parm = {
						pageNum: 1,
						pageSize: 1000
					}
				}
				
				if (item.url && item.type != 'mulSelect') {
					request[item.apiType || 'get'](item.url, parm).then((res) => {
						if (item.parm) {
							res.data.forEach((resm) => {
								if (resm.flag == 1) {
									resm.name = resm.name + '-(已选择过)'
								}
							})
						}
						if (item.look) {
							this.pafList = res[item.dataType] || res.data
						}
						this.actions[0] = res[item.dataType] || res.data
						
						item.actions = res[item.dataType] || res.data
						if (item.filter) {
							let arr = JSON.parse(uni.getStorageSync('userInfoRole')).hospitalList.map(item => item.hospitalId)
							this.actions[0] = this.actions[0].filter(item => arr.includes(item.id))
						}
						
						this.actions[0].forEach((item) => {
							if (item[item.value] == this.itemKeyList[item.modelName]) {
								this.itemKeyList[item.model] = item[item.keyName]
							}
						})
						this.$nextTick(() => {
							if (item.controls == 'select') {
								this.showSex = true
							} else {
								this.showTime = true
							}
						})
						// this.keys = new Date().getTime()
					})
				} else {
					if (item.controls == 'select') {
						this.actions[0] = item.actions[0] || []
						this.showSex = true 
					} else {
						this.showTime = true
					}
				}
				
			},
			showFun(item) {
				item.showSex = true
			},
			sexSelect(e) {
				console.log('adsg2', e)
				// this.indexItem = e.indexs
				this.itemKeyList[this.modelName] = e.value[0][this.value]
				if (this.modelName == 'hospitalList') {
					this.itemKeyList[this.modelName]  = [{hospitalId: e.value[0][this.value]}]
				}
				this.itemKeyList[this.model] = e.value[0][this.keyName]
				// this.itemKeyList[this.value] = e.value[0][this.value]
				if (this.modelName == 'departmentId') {
					this.itemKeyList.doctorId = ''
					this.itemKeyList.doctorName = ''
				}
				if (this.modelName == 'targetZh') {
					// this.itemKeyList[this.modelName] = e.value[0][this.keyName]
					this.itemKeyList[this.model] = e.value[0][this.keyName]
				}
				if (this.parms) {
					if(e.value[0][this.keyName].split('-').length > 1){
						this.itemKeyList[this.model] = e.value[0][this.keyName].split('-')[0]
					} else {
						this.itemKeyList[this.model] = e.value[0][this.keyName]
					}
				}
				this.showSex = false
				this.$refs.formRef.validateField(this.model)
			},
			confirmTime(e) {
				this.itemKeyList[this.model] = this.formatDate(new Date(e.value), 'YYYY-MM-DD HH:ii:ss')
				this.showTime = false
				this.$refs.formRef.validateField(this.model)
				// 
			},
			formatDate(date,formatStr) {
				let arrWeek = ['日', '一', '二', '三', '四', '五', '六'],
					str = formatStr.replace(/yyyy|YYYY/, date.getFullYear()).replace(/yy|YY/, this.$addZero(date.getFullYear() % 100,
						2)).replace(/mm|MM/, this.$addZero(date.getMonth() + 1, 2)).replace(/m|M/g, date.getMonth() + 1).replace(
						/dd|DD/, this.$addZero(date.getDate(), 2)).replace(/d|D/g, date.getDate()).replace(/hh|HH/, this.$addZero(date
						.getHours(), 2)).replace(/h|H/g, date.getHours()).replace(/ii|II/, this.$addZero(date.getMinutes(), 2))
					.replace(/i|I/g, date.getMinutes()).replace(/ss|SS/, this.$addZero(date.getSeconds(), 2)).replace(/s|S/g, date
						.getSeconds()).replace(/w/g, date.getDay()).replace(/W/g, arrWeek[date.getDay()]);
				return str
			 
			},
			$addZero(v, size) {
				for (var i = 0, len = size - (v + "").length; i < len; i++) {
					v = "0" + v
				}
				return v + ""
			},
			formatter(type, value) {
					if (type === 'year') {
							return `${value}年`
					}
					if (type === 'month') {
							return `${value}月`
					}
					if (type === 'day') {
							return `${value}日`
					}
					if (type === 'hour') {
							return `${value}时`
					}
					if (type === 'minute') {
							return `${value}分`
					}
					return value
			},
			confirmFunXz() {
				this.showTimefilter = false
				this.itemKeyList.isUnusual = 1
				this.itemKeyList.unusualReason = this.contentext
				this.$emit('setdata', this.itemKeyList)
			},
			submit() {
				if (this.itemKeyList.filterTimeSta && this.itemKeyList.filterTimeEnd) {
					if(this.itemKeyList.startTime){
						let star = new Date(this.itemKeyList.startTime.replace(/-/g, '/')).getTime()
						let end = new Date(this.itemKeyList.endTime.replace(/-/g, '/')).getTime()
						let starnow = new Date(this.itemKeyList.filterTimeSta.replace(/-/g, '/')).getTime()
						let endnow = new Date(this.itemKeyList.filterTimeEnd.replace(/-/g, '/')).getTime()
						if (star > new Date().getTime()) {
							uni.showToast({
							  title: '任务开始时间不能大于当前时间',
							  icon: "none",
							  duration: 2500,
							})
							return
						}
						if (end > new Date().getTime()) {
							uni.showToast({
							  title: '任务结束时间不能大于当前时间',
							  icon: "none",
							  duration: 2500,
							})
							return
						}
						if (star > end) {
							uni.showToast({
							  title: '任务开始时间不能大于任务结束时间',
							  icon: "none",
							  duration: 2500,
							})
							return
						}
						if (star < starnow) {
							uni.showToast({
							  title: '做任务开始时间不能大于新建任务的开始时间',
							  icon: "none",
							  duration: 2500,
							})
							return
						}
						if (end > endnow) {
							uni.showToast({
							  title: '做任务结束时间不能大于新建任务结束的时间',
							  icon: "none",
							  duration: 2500,
							})
							return
						}
					}
				}
				
				// console.log('this.$refs.formRef', this.$refs.formRef.validate)
				this.$refs.formRef.validate().then(() => {
					this.itemKeyList.photoList = []
					this.itemListNew.forEach((vals) => {
						if(vals.fileList && vals.fileList.length>0){
							vals.fileList.forEach((items) => {
								this.itemKeyList.photoList.push(items)
							})
						}
					})
					// this.itemKeyList.photoList
					// console.log('this.itemKeyList', this.itemKeyList)
					
					// WHY:
					// 拜访和调研：8-18点
					
					// WHY:
					// 会议类的：8-23点
					if (this.itemKeyList.filterTimeSta && this.itemKeyList.filterTimeEnd) {
						let star = new Date(this.itemKeyList.startTime.replace(/-/g, '/')).getTime()
						let end = new Date(this.itemKeyList.endTime.replace(/-/g, '/')).getTime()
						this.contentext = ''
						if (this.itemKeyList.type == 3 || this.itemKeyList.type == 4) {
							if (new Date(this.itemKeyList.startTime.replace(/-/g, '/')).getHours() < 8) {
								// this.showTimefilter = true
								this.contentext += '任务开始时间不能早于8点;'
							}
							if (new Date(this.itemKeyList.endTime.replace(/-/g, '/')).getHours() == 0) {
								// this.showTimefilter = true
								this.contentext += '任务结束时间不能晚于23点;'
							}
							if (end-star < 1200000) {
								// this.showTimefilter = true
								this.contentext += '任务开始时间跟任务结束时间间隔小于20分钟;'
							}
							if (this.contentext) {
								this.contentext = this.contentext
								this.showTimefilter = true
								return
							}
						} else {
							if (new Date(this.itemKeyList.startTime.replace(/-/g, '/')).getHours() < 8) {
								// this.showTimefilter = true
								this.contentext += '任务开始时间不能早于8点;'
							}
							if (new Date(this.itemKeyList.endTime.replace(/-/g, '/')).getHours() >= 18) {
								// this.showTimefilter = true
								this.contentext += '任务结束时间不能晚于18点;'
							}
							if (end-star < 180000) {
								// this.showTimefilter = true
								this.contentext += '任务开始时间跟任务结束时间间隔小于3分钟;'
							}
							if (this.contentext) {
								this.contentext = this.contentext
								this.showTimefilter = true
								return
							}
						}
					}
					
					this.$emit('setdata', this.itemKeyList)
				})
			}
		},
	};
</script>
<style scoped>
	.add_sty {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
		border: 1px solid gray;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
<style lang='scss' scoped>
.mySelect {
    width: 100%;
    .input {
        display: flex;
    }
    
}
.checkbox {
	padding: 15rpx;
	max-height: 50vh;
	overflow: scroll;
	padding-bottom: 85rpx;
}
.btnList {
	position: absolute;
	bottom: 0;
	width: 100%;
	left: 0;
	z-index: 9999;
	display: flex;
	height: 80rpx;
	padding: 0 10rpx;
	box-sizing: border-box;
	background-color: #fff;
}
</style>